package cn.com.czpb.client.module.personal.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import cn.com.czpb.client.R;
import cn.com.czpb.client.custorm.RecycleViewDivider;
import cn.com.czpb.client.model.usercenter.HistoryDataEntity;

import java.util.List;

/**
 * Created by Administrator on 2017/8/16.
 */

public class HistoryDayAdapter extends BaseMultiItemQuickAdapter<HistoryDataEntity, BaseViewHolder> {
    private HistoryAdapter adapter;
    private Context context;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public HistoryDayAdapter(List<HistoryDataEntity> data, Context context) {
        super(data);
        this.context = context;
        addItemType(0, R.layout.item_history);
    }

    @Override
    protected void convert(BaseViewHolder helper, HistoryDataEntity item) {
        switch (helper.getItemViewType()) {
            case 0:
                helper.setText(R.id.tv_item_history, GetDate(item.getFlag(), item.getCount()));
                RecyclerView recyclerView = helper.getView(R.id.recyclerview_history_item);
                adapter = new HistoryAdapter(item.getNewslist(), context);
                recyclerView.setLayoutManager(new LinearLayoutManager(helper.itemView.getContext(), LinearLayoutManager.VERTICAL, false));
                int heigh = (int) mContext.getResources().getDimension(R.dimen.x2);
                recyclerView.addItemDecoration(new RecycleViewDivider(mContext,
                        LinearLayoutManager.HORIZONTAL, heigh,
                        mContext.getResources().getColor(R.color.color_e8e8e8)));
                recyclerView.setAdapter(adapter);
                break;
        }
    }

    private String GetDate(int flag, String count) {
        if (flag == 0) {
            return "今天阅读了 " + count + " 篇文章";
        } else if (flag == 1) {
            return "昨天阅读了 " + count + " 篇文章";
        } else {
            return flag + "天前阅读了 " + count + " 篇文章";
        }
    }
}
